package com.koron.housing.excel;

import cn.hutool.extra.spring.SpringUtil;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.housing.contract.bean.po.HousingContract;
import com.koron.housing.contract.bean.query.ContractQuery;
import com.koron.housing.contract.service.HousingContractService;
import org.koron.ebs.mybatis.ADOConnection;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author jzp
 * @since 2022/6/14
 */
public class HousingInfoAllConvertor extends DictAutoConverter {
    public HousingInfoAllConvertor() {
        super();
        // 转化合同编号
        HousingContractService housingContractService = SpringUtil.getBean(HousingContractService.class);
        ContractQuery contractQuery = new ContractQuery();
        List<HousingContract> list = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), factory -> housingContractService.list(factory, contractQuery), List.class);
        Map<String, String> map = Optional.ofNullable(list)
                .map(l -> l.stream().collect(Collectors.toMap(HousingContract::getId, HousingContract::getCode, (o1, o2) -> o1)))
                .orElse(new HashMap<>());
        putMap("contractId", "合同id", map);
    }

}
